package appli_Oxygene.vues;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import framework.Ressources;
import framework.Utilisateurs;
import reservation.LesRessources;
import utilisateur.Utilisateur;

public class SuppRes extends JFrame {

	private JPanel contentPane;
	JComboBox<String> comboBox;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SuppRes frame = new SuppRes();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SuppRes() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 364, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("S\u00E9lectionnez la ressource \u00E0 supprimer");
		lblNewLabel.setBounds(10, 48, 411, 14);
		contentPane.add(lblNewLabel);	
		comboBox = new JComboBox<>();
		comboBox.setBounds(10, 96, 336, 22);
		remplirCbb();
		contentPane.add(comboBox);

		
		
		JButton btnSupprimer = new JButton("Supprimer");
		btnSupprimer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				supprU();
			}
		});
		btnSupprimer.setBounds(124, 165, 121, 23);
		contentPane.add(btnSupprimer);
	}
	
	public void remplirCbb(){
		LesRessources res=new LesRessources();
		res=Ressources.chargerLesRessources();
		System.out.println(res);
		List r=new ArrayList<>();
		r=res.toutesLesRessources();
		for(int i=0;i<r.size();i++){
			comboBox.addItem(r.get(i).toString());
		}
	}

	public void supprU(){
		Utilisateurs.supprimerUtilisateur(comboBox.getSelectedItem().toString());
		comboBox.removeAllItems();remplirCbb();
	}
	

}
